home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d3 / rettig.arc / TRSOURCE.EXE / DECRYPT.C < prev    next >
C/C++ Source or Header  |  1990-10-22  |  2KB  |  54 lines

  1. /*********
  2. *
  3. * DECRYPT.C
  4. *
  5. * by Leonard Zerman, Tom Rettig    
  6. *
  7. * Placed in the public domain by Tom Rettig Associates, 10/22/1990.
  8. *
  9. *  Syntax: DECRYPT( <string>, <password> )
  10. *  Return: <expC> of <string> decoded according to <password>.
  11. *          Return string will be same length as <string>.
  12. *          Unchanged <string> if <password> is less than 3 characters.
  13. *  Note..: Both parameters are <expC>.
  14. *********/
  15.  
  16. #include "trlib.h"
  17.  
  18. TRTYPE decrypt()
  19. {
  20.    char *pwstr, *instr, *ret;
  21.    int len, pwlen;
  22.  
  23.    if ( PCOUNT == 2 && ISCHAR(1) && ISCHAR(2) )
  24.    {
  25.       instr  = _parc(1);                            /* pointer to string */
  26.       pwstr  = _parc(2);                          /* pointer to password */
  27.       len    = _tr_strlen(instr);                    /* length of string */
  28.       pwlen  = _tr_strlen(pwstr);                  /* length of password */
  29.                                            /* allocate memory for return */
  30.       ret = _tr_allocmem( (unsigned)( len + 1 ) ); 
  31.  
  32.       if ( !( ret ) || pwlen < PW_MIN_LEN )        /* if allocation error */
  33.       {                                        /* or pwlen < 3 characters */
  34.          _retc( instr );              /* return without changing anything */
  35.          return;
  36.       }
  37.  
  38.       _retc( _tr_crypt( instr, pwstr, ret ) ); /* return decrypted string */
  39.       _tr_freemem( ret,(unsigned)( len + 1 )); /* free allocated memory */
  40.  
  41.    }
  42.    else 
  43.    {
  44.  
  45.       if ( ISCHAR(1) )                   /* if error on parameters passed */
  46.          _retc( _parc(1) );                           /* return unchanged */
  47.       else 
  48.          _retc( NULLS );          /* if wrong type of parameters are sent */
  49.  
  50.       return;
  51.    }
  52. }
  53. /* eof decrypt */ 
  54.